Systems and methods for providing messages to multiple subscribers

ABSTRACT

Methods, systems, and apparatus, including computer programs encoded on a computer storage device, for: receiving messages from a plurality of publishers; assigning each of the messages to one of a plurality of channels, wherein each channel comprises an ordered plurality of messages; storing messages of each of the channels in respective storage buffers according to the order, wherein each storage buffer comprises a respective time-to-live of a first time duration; for a particular channel, retrieving messages of the particular channel from respective storage buffers; storing the retrieved messages of the particular channel in a delivery buffer, the delivery buffer comprising data blocks, wherein each data block comprises a respective time-to-live of a second time duration; and providing the messages stored in the delivery buffer to a plurality of subscribers of the particular channel.

CROSS-REFERENCE TO RELATED APPLICATIONS

This application is a continuation of U.S. application Ser. No.15/274,281, filed Sep. 23, 2016, which is hereby incorporated byreference in its entirety.

BACKGROUND

This specification relates to a data communication system and, inparticular, a system that implements real-time, scalablepublish-subscribe messaging.

The publish-subscribe pattern (or “PubSub”) is a data communicationmessaging arrangement implemented by software systems where so-calledpublishers publish messages to topics and so-called subscribers receivethe messages pertaining to particular topics to which they aresubscribed. There can be one or more publishers per topic and publishersgenerally have no knowledge of what subscribers, if any, will receivethe published messages. Some PubSub systems do not cache messages orhave small caches meaning that subscribers may not receive messages thatwere published before the time of subscription to a particular topic.PubSub systems can be susceptible to performance instability duringsurges of message publications or as the number of subscribers to aparticular topic increases.

SUMMARY

In various implementations, the systems and methods described hereinutilize a shared structure (i.e., a “fast buffer”) to store message datathat can be read by multiple subscribers simultaneously. To avoid issuesassociated with locking, the systems and methods utilize a “lock-free”or non-blocking approach. Subscribers are able to grab many pieces ofdata without blocking or figuring out where to read from and up to whichpoint in the fast buffer.

The systems and methods provide many benefits compared to priorapproaches. For example, publishers are not limited by subscribers orassociated subscription logic and have a stable publishing speed,regardless of how many subscribers exist, if any. This property of thesystem can be achieved, for example, by making publishing andsubscribing components and/or processes independent from each other. Insome instances, the publishing and subscribing components can shareinformation through lock-free memory writes and reads, for example,using the fast buffer approach described herein. Alternatively oradditionally, publishing and subscribing components and/or processes canbe configured to utilize different physical cores, such that, forexample, publishing and subscribing components interact solely through amemory controller and bus, which is typically fast and/or does notpresent a bottleneck.

Alternatively or additionally, system flexibility allows publishers tobe prioritized (or deprioritized) over subscribers, if desired. Inpreferred examples, the fast buffer has or utilizes loosely coupledpublishing and subscribing loops. This allows a publishing speed to bedifferent from a subscribing speed, if desired, and/or for each speed tobe chosen or prioritized, for example, according system load. Whenpublishing activity is high and/or it is preferable to not limit thepublishing activity, for example, the publishing loop can be prioritizedover the subscribing loop. To achieve such prioritization, thepublishing loop can be made to spin as if there were no subscribers(e.g., the publishing loop can be processed faster than the subscribingloop is processed). In other words, it can be desirable to not block orlimit publishers by allowing the system to pass as much publishedmessage data as possible, even if subscribers are unable to keep up withor receive all of the message data. Alternatively or additionally, whensubscribing activity is high, it can be desirable to not block or limitsubscribers and/or to apply automatic back-pressure on publishers, suchthat publishing activity is reduced. Such prioritization can beachieved, for example, by creating two worker pools (e.g., one pool forpublishers and one pool for subscribers) and using an operating systemkernel scheduler prioritization mechanism to set different priorities tothreads in the two pools. Other approaches for prioritizing ordeprioritzing publishers and subscribers are contemplated.

A further advantage of the systems and methods is that subscribers canutilize data aggregation and can define how much data to aggregate. Ingeneral, use of data aggregation and/or aggregation size optimizationcan help achieve better performance characteristics and/or reduce memoryusage. For example, when delivering messages, the messages can begrouped into blocks or batches (e.g., a comma-separated list of messagesin the fast buffer). When preparing message data to be sent, the systemsand methods can decide how many messages to aggregate for the nextblock. The sizes of packets exchanged in a connection can depend onconnection properties (e.g., bandwidth and/or latency) and/or on a stateof a TCP connection. In some instances, this allows the process ofcollecting messages for the connection to aggregate more messages in ablock to produce a bigger packet, thereby better utilizing networkcapacity and providing higher throughput with less overhead.

Another benefit of the systems and methods is that, depending on messageactivity, subscribers can change the frequency of data reading byfinding an optimal balance between performance and latency. For example,using the notifier approach described herein, channels with high messageactivity can be actively monitored for new messages, while channels withlow message activity can receive less active monitoring. Subscribers arepreferably isolated and do not affect one other. If one subscriber isslower than a message stream, other subscribers are generally unaffectedby the slow subscriber and can keep up with the message stream.

A further benefit of the systems and methods is that modularity isincreased, which allows system components to be implementedindependently. Interaction is preferably done through memory, sosubscribers can be placed on separate individual processes to access thefast buffer. In alternative approaches, multiple logical parts of asystem can be coupled tightly to reduce interface overhead (e.g.,preparing data to be exported and parsing on input) and/or to makechanges more granular and precise. The drawback of such approaches isreduced isolation, reduced reliability and, in general, less efficiency(e.g., due to load of one component influencing other components). Theopposite approach, used in examples of the systems and methods describedherein, is to isolate components from each other and to achieveincreased reliability and efficiency and better management andprioritization of system components. In general, isolation is moreeffective when the cost of overhead is low or at least acceptable. Inthe systems and methods, for example, the cost of overhead is generallylow because processes can communicate by writing to and reading from thefast buffer. The systems and methods can benefit from such modularitywith little or no added cost. In some implementations, when sharedmemory at the operating system level is used, publishers and subscriberscan be implemented in different processes and/or can start usingimplementations written in different languages. In general, interactionthrough use of the fast buffer limits communication to only twooperations: writing to the memory and reading from the memory. The useof messages, signals, locks, and/or synchronization primitives can beavoided. As discussed herein, test results indicate that the systems andmethods greatly improve message transfer rates from publishers tosubscribers.

In general, one aspect of the subject matter described in thisspecification can be embodied in computer-implemented methods thatinclude the actions of: receiving a plurality of messages from aplurality of publishers; assigning each of the messages to one of aplurality of channels, wherein each channel includes an orderedplurality of messages; storing messages of each of the channels in oneor more respective storage buffers according to the order, wherein eachstorage buffer includes a respective time-to-live (TTL) of a first timeduration; for a particular channel, retrieving messages of theparticular channel from respective storage buffers (e.g., those havingtimes-to-live that have not expired and according to the order); storingthe retrieved messages of the particular channel in a delivery bufferaccording to the order, the delivery buffer including one or more datablocks, wherein each data block includes a respective time-to-live of asecond time duration (e.g., that is longer than the first timeduration); and providing the messages stored in the delivery buffer to aplurality of subscribers of the particular channel. Other embodiments ofthis aspect include corresponding systems, apparatus, storage devices,and computer programs.

These and other aspects can optionally include one or more of thefollowing features. Providing the messages stored in the delivery bufferto the plurality of subscribers of the particular channel can furtherinclude determining a connection status of a particular subscriber and,based thereon, providing one or more of the messages stored in thedelivery buffer to the particular subscriber. The aspect can furtherinclude determining that the particular subscriber has a currentconnection to the particular channel, and, based thereon, providing tothe particular subscriber one or more messages stored in the deliverybuffer including messages stored in one or more data blocks havingrespective times-to-live that have expired. The aspect can furtherinclude determining that the particular subscriber does not have acurrent connection to the particular channel and, based thereon, (i)providing to the particular subscriber one or more messages stored inone or more of the data blocks having respective times-to-live that havenot expired, and (ii) preventing the particular subscriber fromreceiving one or more messages stored in one or more data blocks havingrespective times-to-live that have expired. Storing the retrievedmessages of the particular channel in the delivery buffer can includestoring retrieved messages of the particular channel earlier in theorder in data blocks having times-to-live that will expire sooner thandata blocks used to store retrieved messages of the particular channellater in the order. The delivery buffer can include a linked list of thedata blocks. Retrieved messages last in the order of the particularchannel can be stored in a tail data block of the linked list. Storingthe retrieved messages of the particular channel in the delivery buffercan further include removing from the linked list one or more datablocks at a head of the linked list. The removed data blocks can includerespective times-to-live that have expired (e.g., for exceeding aspecified time period). The delivery buffer can reside on a firstcomputing node. The messages stored in the delivery buffer can beprovided to each of the plurality of subscribers through a respectivecomputing process residing on the first computing node. The storagebuffers can reside on respective second computing nodes that aredifferent from the first computing node. In some examples, the deliverybuffer can include a visible area and an invisible area. A subscriberwith a pre-existing connection (e.g., a subscriber that was previouslygranted read access to the delivery buffer and has been reading from thedelivery buffer) may be permitted to access data from both the visiblearea and the invisible area. A subscriber with a new connection (e.g., asubscriber that was recently granted read access and has not yet startedreading from the delivery buffer) may be permitted to access data fromthe visible area and not be permitted to access data from the invisiblearea.

The details of one or more embodiments of the subject matter describedin this specification are set forth in the accompanying drawings and thedescription below. Other features, aspects, and advantages of thesubject matter will become apparent from the description, the drawings,and the claims.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1A illustrates an example system that supports the PubSubcommunication pattern.

FIG. 1B illustrates functional layers of software on an example clientdevice.

FIG. 2 is a diagram of an example messaging system.

FIG. 3A is a data flow diagram of an example method for writing data toa streamlet.

FIG. 3B is a data flow diagram of an example method for reading datafrom a streamlet.

FIG. 4A is a data flow diagram of an example method for publishingmessages to a channel of a messaging system.

FIG. 4B is a data flow diagram of an example method for subscribing to achannel of a messaging system.

FIG. 4C is an example data structure for storing messages of a channelof a messaging system.

FIG. 5 is a schematic diagram of an MX Node retrieving messages from a Qnode and providing the retrieved messages to a subscriber of a messagingsystem.

FIG. 6 shows example data blocks of a fast buffer in an MX node of amessaging system at different time instances.

FIG. 7 is a flowchart of an example method for sending message data to aplurality of subscribers.

Like reference numbers and designations in the various drawings indicatelike elements.

DETAILED DESCRIPTION

FIG. 1A illustrates an example system 100 that supports the PubSubcommunication pattern. Publisher clients (e.g., Publisher 1) can publishmessages to named channels (e.g., “Channel 1”) by way of the system 100.A message can comprise any type of information including one or more ofthe following: text, image content, sound content, multimedia content,video content, binary data, and so on. Other types of message data arepossible. Subscriber clients (e.g., Subscriber 2) can subscribe to anamed channel using the system 100 and start receiving messages whichoccur after the subscription request or from a given position (e.g., amessage number or time offset). A client can be both a publisher and asubscriber.

Depending on the configuration, a PubSub system can be categorized asfollows:

-   -   One to One (1:1). In this configuration there is one publisher        and one subscriber per channel. A typical use case is private        messaging.    -   One to Many (1:N). In this configuration there is one publisher        and multiple subscribers per channel. Typical use cases are        broadcasting messages (e.g., stock prices).    -   Many to Many (M:N). In this configuration there are many        publishers publishing to a single channel. The messages are then        delivered to multiple subscribers. Typical use cases are map        applications.

There is no separate operation needed to create a named channel. Achannel is created implicitly when the channel is subscribed to or whena message is published to the channel. In some implementations, channelnames can be qualified by a name space. A name space comprises one ormore channel names. Different name spaces can have the same channelnames without causing ambiguity. The name space name can be a prefix ofa channel name where the name space and channel name are separated by adot or other suitable separator. In some implementations, name spacescan be used when specifying channel authorization settings. Forinstance, the messaging system 100 may have app1.foo andapp1.system.notifications channels where “app1” is the name of the namespace. The system can allow clients to subscribe and publish to theapp1.foo channel. However, clients can only subscribe to, but notpublish to the app1.system.notifications channel.

FIG. 1B illustrates functional layers of software on an example clientdevice. A client device (e.g., client 102) is a data processingapparatus such as, for example, a personal computer, a laptop computer,a tablet computer, a smart phone, a smart watch, or a server computer.Other types of client devices are possible. The application layer 104comprises the end-user application(s) that will integrate with thePubSub system 100. The messaging layer 106 is a programmatic interfacefor the application layer 104 to utilize services of the system 100 suchas channel subscription, message publication, message retrieval, userauthentication, and user authorization. In some implementations, themessages passed to and from the messaging layer 106 are encoded asJavaScript Object Notation (JSON) objects. Other message encodingschemes are possible.

The operating system 108 layer comprises the operating system softwareon the client 102. In various implementations, messages can be sent andreceived to/from the system 100 using persistent or non-persistentconnections. Persistent connections can be created using, for example,network sockets. A transport protocol such as TCP/IP layer 112implements the Transport Control Protocol/Internet Protocolcommunication with the system 100 that can be used by the messaginglayer 106 to send messages over connections to the system 100. Othercommunication protocols are possible including, for example, UserDatagram Protocol (UDP). In further implementations, an optionalTransport Layer Security (TLS) layer 110 can be employed to ensure theconfidentiality of the messages.

FIG. 2 is a diagram of an example messaging system 100. The system 100provides functionality for implementing PubSub communication patterns.The system comprises software components and storage that can bedeployed at one or more data centers 122 in one or more geographiclocations, for example. The system comprises MX nodes (e.g., MX nodes ormultiplexer nodes 202, 204 and 206), Q nodes (e.g., Q nodes or queuenodes 208, 210 and 212), one or more channel manager nodes (e.g.,channel managers 214, 215), and optionally one or more C nodes (e.g., Cnodes or cache nodes 220 and 222). Each node can execute in a virtualmachine or on a physical machine (e.g., a data processing apparatus).Each MX node serves as a termination point for one or more publisherand/or subscriber connections through the external network 216. Theinternal communication among MX nodes, Q nodes, C nodes, and the channelmanager, is conducted over an internal network 218, for example. By wayof illustration, MX node 204 can be the terminus of a subscriberconnection from client 102. Each Q node buffers channel data forconsumption by the MX nodes. An ordered sequence of messages publishedto a channel is a logical channel stream. For example, if three clientspublish messages to a given channel, the combined messages published bythe clients comprise a channel stream. Messages can be ordered in achannel stream, for example, by time of publication by the client, bytime of receipt by an MX node, or by time of receipt by a Q node. Otherways for ordering messages in a channel stream are possible. In the casewhere more than one message would be assigned to the same position inthe order, one of the messages can be chosen (e.g., randomly) to have alater sequence in the order. Each channel manager node is responsiblefor managing Q node load by splitting channel streams into so-calledstreamlets. Streamlets are discussed further below. The optional C nodesprovide caching and load removal from the Q nodes.

In the example messaging system 100, one or more client devices(publishers and/or subscribers) establish respective persistentconnections (e.g., TCP connections) to an MX node (e.g., MX node 204).The MX node serves as a termination point for these connections. Forinstance, external messages (e.g., between respective client devices andthe MX node) carried by these connections can be encoded based on anexternal protocol (e.g., JSON). The MX node terminates the externalprotocol and translates the external messages to internal communication,and vice versa. The MX nodes publish and subscribe to streamlets onbehalf of clients. In this way, an MX node can multiplex and mergerequests of client devices subscribing for or publishing to the samechannel, thus representing multiple client devices as one, instead ofone by one.

In the example messaging system 100, a Q node (e.g., Q node 208) canstore one or more streamlets of one or more channel streams. A streamletis a data buffer for a portion of a channel stream. A streamlet willclose to writing when its storage is full. A streamlet will close toreading and writing and be de-allocated when its time-to-live (TTL) hasexpired. By way of illustration, a streamlet can have a maximum size of1 MB and a TTL of three minutes. Different channels can have streamletslimited by different sizes and/or by different TTLs. For instance,streamlets in one channel can exist for up to three minutes, whilestreamlets in another channel can exist for up to 10 minutes. In variousimplementations, a streamlet corresponds to a computing process runningon a Q node. The computing process can be terminated after thestreamlet's TTL has expired, thus freeing up computing resources (forthe streamlet) back to the Q node, for example.

When receiving a publish request from a client device, an MX node (e.g.,MX node 204) makes a request to a channel manager (e.g., channel manager214) to grant access to a streamlet to write the message beingpublished. Note, however, that if the MX node has already been grantedwrite access to a streamlet for the channel (and the channel has notbeen closed to writing), the MX node can write the message to thatstreamlet without having to request a grant to access the streamlet.Once a message is written to a streamlet for a channel, the message canbe read by MX nodes and provided to subscribers of that channel.

Similarly, when receiving a channel subscription request from a clientdevice, an MX node makes a request to a channel manager to grant accessto a streamlet for the channel from which messages are read. If the MXnode has already been granted read access to a streamlet for the channel(and the channel's TTL has not been closed to reading) the MX node canread messages from the streamlet without having to request a grant toaccess the streamlet. The read messages can then be forwarded to clientdevices that have subscribed to the channel. In various implementations,messages read from streamlets are cached by MX nodes so that MX nodescan reduce the number of times needed to read from the streamlets.

By way of illustration, an MX node can request a grant from the channelmanager that allows the MX node to store a block of data into astreamlet on a particular Q node that stores streamlets of theparticular channel. Example streamlet grant request and grant datastructures are as follows:

StreamletGrantRequest={

-   -   “channel”: string( )    -   “mode”: “read” | “write”    -   “position”: 0

}

StreamletGrantResponse={

-   -   “streamlet-id”: “abcdef82734987”,    -   “limit-size”: 2000000, #2 megabytes max    -   “limit-msgs”: 5000, #5 thousand messages max    -   “limit-life”: 4000, # the grant is valid for 4 seconds    -   “q-node”: string( )    -   “position”: 0

}

The StreamletGrantRequest data structure stores the name of the streamchannel and a mode indicating whether the MX node intends on readingfrom or writing to the streamlet. The MX node sends theStreamletGrantRequest to a channel manager node. The channel managernode, in response, sends the MX node a StreamletGrantResponse datastructure. The StreamletGrantResponse contains an identifier of thestreamlet (streamlet-id), the maximum size of the streamlet(limit-size), the maximum number of messages that the streamlet canstore (limit-msgs), the TTL (limit-life), and an identifier of a Q node(q-node) on which the streamlet resides. The StreamletGrantRequest andStreamletGrantResponse can also have a position field that points to aposition in a streamlet (or a position in a channel) for reading fromthe streamlet.

A grant becomes invalid once the streamlet has closed. For example, astreamlet is closed to reading and writing once the streamlet's TTL hasexpired and a streamlet is closed to writing when the streamlet'sstorage is full. When a grant becomes invalid, the MX node can request anew grant from the channel manager to read from or write to a streamlet.The new grant will reference a different streamlet and will refer to thesame or a different Q node depending on where the new streamlet resides.

FIG. 3A is a data flow diagram of an example method for writing data toa streamlet in various implementations. In FIG. 3A, when an MX node(e.g., MX node 202) request to write to a streamlet is granted by achannel manager (e.g., channel manager 214), as described before, the MXnode establishes a Transmission Control Protocol (TCP) connection withthe Q node (e.g., Q node 208) identified in the grant response receivedfrom the channel manager (302). A streamlet can be written concurrentlyby multiple write grants (e.g., for messages published by multiplepublisher clients). Other types of connection protocols between the MXnode and the Q node are possible.

The MX node then sends a prepare-publish message with an identifier of astreamlet that the MX node wants to write to the Q node (304). Thestreamlet identifier and Q node identifier can be provided by thechannel manager in the write grant as described earlier. The Q nodehands over the message to a handler process 301 (e.g., a computingprocess running on the Q node) for the identified streamlet (306). Thehandler process can send to the MX node an acknowledgement (308). Afterreceiving the acknowledgement, the MX node starts writing (publishing)messages (e.g., 310, 312, 314, and 318) to the handler process, which inturns stores the received data in the identified streamlet. The handlerprocess can also send acknowledgements (316, 320) to the MX node for thereceived data. In some implementations, acknowledgements can bepiggy-backed or cumulative. For instance, the handler process can sendto the MX node an acknowledgement for every predetermined amount of datareceived (e.g., for every 100 messages received) or for everypredetermined time period (e.g., for every one millisecond). Otheracknowledgement scheduling algorithms, such as Nagle's algorithm, can beused.

If the streamlet can no longer accept published data (e.g., when thestreamlet is full), the handler process sends a Negative-Acknowledgement(NAK) message (330) indicating a problem, following by an EOF(end-of-file) message (332). In this way, the handler process closes theassociation with the MX node for the publish grant. The MX node can thenrequest a write grant for another streamlet from a channel manager ifthe MX node has additional messages to store.

FIG. 3B is a data flow diagram of an example method for reading datafrom a streamlet in various implementations. In FIG. 3B, an MX node(e.g., MX node 204) sends to a channel manager (e.g., channel manager214) a request for reading a particular channel starting from aparticular message or time offset in the channel. The channel managerreturns to the MX node a read grant including an identifier of astreamlet containing the particular message, a position in the streamletcorresponding to the particular message, and an identifier of a Q node(e.g., Q node 208) containing the particular streamlet. The MX node thenestablishes a TCP connection with the Q node (352). Other types ofconnection protocols between the MX node and the Q node are possible.

The MX node then sends to the Q node a subscribe message (354) with theidentifier of the streamlet (in the Q node) and the position in thestreamlet from which the MX node wants to read (356). The Q node handsover the subscribe message to a handler process 351 for the streamlet(356). The handler process can send to the MX node an acknowledgement(358). The handler process then sends messages (360, 364, 366), startingat the position in the streamlet, to the MX node. In someimplementations, the handler process can send all of the messages in thestreamlet to the MX node. After sending the last message in a particularstreamlet, the handler process can send a notification of the lastmessage to the MX node. The MX node can send to the channel manageranother request for another streamlet containing a next message in theparticular channel.

If the particular streamlet is closed (e.g., after its TTL has expired),the handler process can send an unsubscribe message (390), followed byan EOF message (392), to close the association with the MX node for theread grant. The MX node can close the association with the handlerprocess when the MX node moves to another streamlet for messages in theparticular channel (e.g., as instructed by the channel manager). The MXnode can also close the association with the handler process if the MXnode receives an unsubscribe message from a corresponding client device.

In various implementations, a streamlet can be written into and readfrom at the same time instance. For instance, there can be a valid readgrant and a valid write grant at the same time instance. In variousimplementations, a streamlet can be read concurrently by multiple readgrants (e.g., for channels subscribed to by multiple publisher clients).The handler process of the streamlet can order messages from concurrentwrite grants based on, for example, time-of-arrival, and store themessages based on the order. In this way, messages published to achannel from multiple publisher clients can be serialized and stored ina streamlet of the channel.

In the messaging system 100, one or more C nodes (e.g., C node 220) canoffload data transfers from one or more Q nodes. For instance, if thereare many MX nodes requesting streamlets from Q nodes for a particularchannel, the streamlets can be offloaded and cached in one or more Cnodes. The MX nodes (e.g., as instructed by read grants from a channelmanager) can read the streamlets from the C nodes instead.

As described above, messages for a channel in the messaging system 100are ordered in a channel stream. A channel manager (e.g., channelmanager 214) splits the channel stream into fixed-sized streamlets thateach reside on a respective Q node. In this way, storing a channelstream can be shared among many Q nodes; each Q node stores a portion(one or more streamlets) of the channel stream. More particularly, astreamlet can be stored in, for example, registers and/or dynamic memoryelements associated with a computing process on a Q node, thus avoidingthe need to access persistent, slower storage devices such as harddisks. This results in faster message access. The channel manager canalso balance load among Q nodes in the messaging system 100 bymonitoring respective workloads of the Q nodes and allocating streamletsin a way that avoids overloading any one Q node.

In various implementations, a channel manager maintains a listidentifying each active streamlet, the respective Q node on which thestreamlet resides, an identification of the position of the firstmessage in the streamlet, and whether the streamlet is closed forwriting. In some implementations, Q nodes notify the channel manager andany MX nodes that are publishing to a streamlet that the streamlet isclosed due to being full or when the streamlet's TTL has expired. When astreamlet is closed, the streamlet remains on the channel manager's listof active streamlets until the streamlet's TTL has expired so that MXnodes can continue to retrieve messages from the streamlet.

When an MX node requests a write grant for a given channel and there isnot a streamlet for the channel that can be written to, the channelmanager allocates a new streamlet on one of the Q nodes and returns theidentity of the streamlet and the Q node in the StreamletGrantResponse.Otherwise, the channel manager returns the identity of the currentlyopen for writing streamlet and corresponding Q node in theStreamletGrantResponse. MX nodes can publish messages to the streamletuntil the streamlet is full or the streamlet's TTL has expired, afterwhich a new streamlet can be allocated by the channel manager.

When an MX node requests a read grant for a given channel and there isnot a streamlet for the channel that can be read from, the channelmanager allocates a new streamlet on one of the Q nodes and returns theidentity of the streamlet and the Q node in the StreamletGrantResponse.Otherwise, the channel manager returns the identity of the streamlet andQ node that contains the position from which the MX node wishes to read.The Q node can then begin sending messages to the MX node from thestreamlet beginning at the specified position until there are no moremessages in the streamlet to send. When a new message is published to astreamlet, MX nodes that have subscribed to that streamlet will receivethe new message. If a streamlet's TTL has expired, the handler process351 sends an EOF message (392) to any MX nodes that are subscribed tothe streamlet.

As described earlier in reference to FIG. 2, the messaging system 100can include multiple channel managers (e.g., channel managers 214, 215).Multiple channel managers provide resiliency and prevent single point offailure. For instance, one channel manager can replicate lists ofstreamlets and current grants it maintains to another “slave” channelmanager. As for another example, multiple channel managers cancoordinate operations between them using distributed consensusprotocols, such as, for example, Paxos or Raft protocols.

FIG. 4A is a data flow diagram of an example method for publishingmessages to a channel of a messaging system. In FIG. 4A, publishers(e.g., publisher clients 402, 404, 406) publish messages to themessaging system 100 described earlier in reference to FIG. 2. Forinstance, publishers 402 respectively establish connections 411 and sendpublish requests to the MX node 202. Publishers 404 respectivelyestablish connections 413 and send publish requests to the MX node 206.Publishers 406 respectively establish connections 415 and send publishrequests to the MX node 204. Here, the MX nodes can communicate (417)with a channel manager (e.g., channel manager 214) and one or more Qnodes (e.g., Q nodes 212 and 208) in the messaging system 100 via theinternal network 218.

By way of illustration, each publish request (e.g., in JSON key/valuepairs) from a publisher to an MX node includes a channel name and amessage. The MX node (e.g., MX node 202) can assign the message in thepublish request to a distinct channel in the messaging system 100 basedon the channel name (e.g., “foo”) of the publish request. The MX nodecan confirm the assigned channel with the channel manager 214. If thechannel (specified in the subscribe request) does not yet exist in themessaging system 100, the channel manager can create and maintain a newchannel in the messaging system 100. For instance, the channel managercan maintain a new channel by maintaining a list identifying each activestreamlet of the channel's stream, the respective Q node on which thestreamlet resides, and identification of the positions of the first andlast messages in the streamlet as described earlier.

For messages of a particular channel, the MX node can store the messagesin one or more buffers or streamlets in the messaging system 100. Forinstance, the MX node 202 receives from the publishers 402 requests topublish messages M11, M12, M13, and M14 to a channel foo. The MX node206 receives from the publishers 404 requests to publish messages M78and M79 to the channel foo. The MX node 204 receives from the publishers406 requests to publish messages M26, M27, M28, M29, M30, and M31 to thechannel foo.

The MX nodes can identify one or more streamlets for storing messagesfor the channel foo. As described earlier, each MX node can request awrite grant from the channel manager 214 that allows the MX node tostore the messages in a streamlet of the channel foo. For instance, theMX node 202 receives a grant from the channel manager 214 to writemessages M11, M12, M13, and M14 to a streamlet 4101 on the Q node 212.The MX node 206 receives a grant from the channel manager 214 to writemessages M78 and M79 to the streamlet 4101. Here, the streamlet 4101 isthe last one (at the moment) of a sequence of streamlets of the channelstream 430 storing messages of the channel foo. The streamlet 4101 hasmessages (421) of the channel foo that were previously stored in thestreamlet 4101, but is still open, i.e., the streamlet 4101 still hasspace for storing more messages and the streamlet's TTL has not expired.

The MX node 202 can arrange the messages for the channel foo based onthe respective time that each message was received by the MX node 202,e.g., M11, M13, M14, M12 (422), and store the received messages asarranged in the streamlet 4101. That is, the MX node 202 receives M11first, followed by M13, M14, and M12. Similarly, the MX node 206 canarrange the messages for the channel foo based on their respective timethat each message was received by the MX node 206, e.g., M78, M79 (423),and store the received messages as arranged in the streamlet 4101. Otherarrangements or ordering of the messages for the channel are possible.

The MX node 202 (or MX node 206) can store the received messages usingthe method for writing data to a streamlet described earlier inreference to FIG. 3A, for example. In various implementations, the MXnode 202 (or MX node 206) can buffer (e.g., in a local data buffer) thereceived messages for the channel foo and store the received messages ina streamlet for the channel foo (e.g., streamlet 4101) when the bufferedmessages reach a predetermined number or size (e.g., 100 messages) orwhen a predetermined time (e.g., 50 milliseconds) has elapsed. Forinstance, the MX node 202 can store in the streamlet 100 messages at atime or in every 50 milliseconds. Other acknowledgement schedulingalgorithms, such as Nagle's algorithm, can be used.

In various implementations, the Q node 212 (e.g., a handler process)stores the messages of the channel foo in the streamlet 4101 in theorder as arranged by the MX node 202 and MX node 206. The Q node 212stores the messages of the channel foo in the streamlet 4101 in theorder the Q node 212 receives the messages. For instance, assume thatthe Q node 212 receives messages M78 (from the MX node 206) first,followed by messages M11 and M13 (from the MX node 202), M79 (from theMX node 206), and M14 and M12 (from the MX node 202). The Q node 212stores in the streamlet 4101 the messages in the order as received,e.g., M78, M11, M13, M79, M14, and M12, immediately after the messages421 that are already stored in the streamlet 4101. In this way, messagespublished to the channel foo from multiple publishers (e.g., 402, 404)can be serialized in a particular order and stored in the streamlet 4101of the channel foo. Different subscribers that subscribe to the channelfoo will receive messages of the channel foo in the same particularorder, as will be described in more detail in reference to FIG. 4B.

In the example of FIG. 4A, at a time instance after the message M12 wasstored in the streamlet 4101, the MX node 204 requests a grant from thechannel manager 214 to write to the channel foo. The channel manager 214provides the MX node 204 a grant to write messages to the streamlet4101, as the streamlet 4101 is still open for writing. The MX node 204arranges the messages for the channel foo based on the respective timethat each message was received by the MX node 204, e.g., M26, M27, M31,M29, M30, M28 (424), and stores the messages as arranged for the channelfoo.

By way of illustration, assume that the message M26 is stored to thelast available position of the streamlet 4101. As the streamlet 4101 isnow full, the Q node 212 sends to the MX node 204 a NAK message,following by an EOF message, to close the association with the MX node204 for the write grant, as described earlier in reference to FIG. 3A.The MX node 204 then requests another write grant from the channelmanager 214 for additional messages (e.g., M27, M31, and so on) for thechannel foo.

The channel manager 214 can monitor available Q nodes in the messagingsystem 100 for their respective workloads (e.g., how many streamlets areresiding in each Q node). The channel manager 214 can allocate astreamlet for the write request from the MX node 204 such thatoverloading (e.g., too many streamlets or too many read or write grants)can be avoided for any given Q node. For instance, the channel manager214 can identify a least loaded Q node in the messaging system 100 andallocate a new streamlet on the least loaded Q node for write requestsfrom the MX node 204. In the example of FIG. 4A, the channel manager 214allocates a new streamlet 4102 on the Q node 208 and provides a writegrant to the MX node 204 to write messages for the channel foo to thestreamlet 4102. As shown in FIG. 4A, the Q node stores in the streamlet4102 the messages from the MX node 204 in an order as arranged by the MXnode 204: M27, M31, M29, M30, and M28 (assuming that there is no otherconcurrent write grant for the streamlet 4102 at the moment).

When the channel manager 214 allocates a new streamlet (e.g., streamlet4102) for a request for a grant from an MX node (e.g., MX node 204) towrite to a channel (e.g., foo), the channel manager 214 assigns to thestreamlet its TTL, which will expire after TTLs of other streamlets thatare already in the channel's stream. For instance, the channel manager214 can assign to each streamlet of the channel foo's channel stream aTTL of 3 minutes when allocating the streamlet. That is, each streamletwill expire 3 minutes after it is allocated (created) by the channelmanager 214. Since a new streamlet is allocated after a previousstreamlet is closed (e.g., filled entirely or expired), in this way, thechannel foo's channel stream comprises streamlets that each expiressequentially after its previous streamlet expires. For instance, asshown in an example channel stream 430 of the channel foo in FIG. 4A,streamlet 4098 and streamlets before 4098 have expired (as indicated bythe dotted-lined gray-out boxes). Messages stored in these expiredstreamlets are not available for reading for subscribers of the channelfoo. Streamlets 4099, 4100, 4101, and 4102 are still active (notexpired). The streamlets 4099, 4100, and 4101 are closed for writing,but still are available for reading. The streamlet 4102 is available forreading and writing, at the moment when the message M28 was stored inthe streamlet 4102. At a later time, the streamlet 4099 will expire,following by the streamlets 4100, 4101, and so on.

FIG. 4B is a data flow diagram of an example method for subscribing to achannel of a messaging system. In FIG. 4B, a subscriber 480 establishesa connection 462 with an MX node 461 of the messaging system 100.Subscriber 482 establishes a connection 463 with the MX node 461.Subscriber 485 establishes a connection 467 with an MX node 468 of themessaging system 100. Here, the MX nodes 461 and 468 can respectivelycommunicate (464) with the channel manager 214 and one or more Q nodesin the messaging system 100 via the internal network 218.

A subscriber (e.g., subscriber 480) can subscribe to the channel foo ofthe messaging system 100 by establishing a connection (e.g., 462) andsending a request for subscribing to messages of the channel foo to anMX node (e.g., MX node 461). The request (e.g., in JSON key/value pairs)can include a channel name, such as, for example, “foo.” When receivingthe subscribe request, the MX node 461 can send to the channel manager214 a request for a read grant for a streamlet in the channel foo'schannel stream.

By way of illustration, assume that at the current moment the channelfoo's channel stream 431 includes active streamlets 4102, 4103, and4104, as shown in FIG. 4B. The streamlets 4102 and 4103 each are full.The streamlet 4104 stores messages of the channel foo, including thelast message (at the current moment) stored at a position 47731.Streamlets 4101 and streamlets before 4101 are invalid, as theirrespective TTLs have expired. Note that the messages M78, M11, M13, M79,M14, M12, and M26 stored in the streamlet 4101, described earlier inreference to FIG. 4A, are no longer available for subscribers of thechannel foo, since the streamlet 4101 is no longer valid, as its TTL hasexpired. As described earlier, each streamlet in the channel foo'schannel stream has a TTL of 3 minutes, thus only messages (as stored instreamlets of the channel foo) that are published to the channel foo(i.e., stored into the channel's streamlets) no earlier than 3 minutesfrom the current time can be available for subscribers of the channelfoo.

The MX node 461 can request a read grant for all available messages inthe channel foo, for example, when the subscriber 480 is a newsubscriber to the channel foo. Based on the request, the channel manager214 provides the MX node 461 a read grant to the streamlet 4102 (on theQ node 208) that is the earliest streamlet in the active streamlets ofthe channel foo (i.e., the first in the sequence of the activestreamlets). The MX node 461 can retrieve messages in the streamlet 4102from the Q node 208, using the method for reading data from a streamletdescribed earlier in reference to FIG. 3B, for example. Note that themessages retrieved from the streamlet 4102 maintain the same order asstored in the streamlet 4102. However, other arrangements or ordering ofthe messages in the streamlet are possible. In various implementations,when providing messages stored in the streamlet 4102 to the MX node 461,the Q node 208 can buffer (e.g., in a local data buffer) the messagesand send the messages to the MX node 461 when the buffer messages reacha predetermined number or size (e.g., 200 messages) or a predeterminedtime (e.g., 50 milliseconds) has elapsed. For instance, the Q node 208can send the channel foo's messages (from the streamlet 4102) to the MXnode 461 200 messages at a time or in every 50 milliseconds. Otheracknowledgement scheduling algorithms, such as Nagle's algorithm, can beused.

After receiving the last message in the streamlet 4102, the MX node 461can send an acknowledgement to the Q node 208, and send to the channelmanager 214 another request (e.g., for a read grant) for the nextstreamlet in the channel stream of the channel foo. Based on therequest, the channel manager 214 provides the MX node 461 a read grantto the streamlet 4103 (on Q node 472) that logically follows thestreamlet 4102 in the sequence of active streamlets of the channel foo.The MX node 461 can retrieve messages stored in the streamlet 4103,e.g., using the method for reading data from a streamlet describedearlier in reference to FIG. 3B, until it retrieves the last messagestored in the streamlet 4103. The MX node 461 can send to the channelmanager 214 yet another request for a read grant for messages in thenext streamlet 4104 (on Q node 474). After receiving the read grant, theMX node 461 retrieves message of the channel foo stored in the streamlet4104, until the last message at the position 47731. Similarly, the MXnode 468 can retrieve messages from the streamlets 4102, 4103, and 4104(as shown with dotted arrows in FIG. 4B), and provide the messages tothe subscriber 485.

The MX node 461 can send the retrieved messages of the channel foo tothe subscriber 480 (via the connection 462) while receiving the messagesfrom the Q node 208, 472, or 474. In various implementations, the MXnode 461 can store the retrieved messages in a local buffer. In thisway, the retrieved messages can be provided to another subscriber (e.g.,subscriber 482) when the other subscriber subscribes to the channel fooand requests the channel's messages. The MX node 461 can remove messagesstored in the local buffer that each has a time of publication that hasexceeded a predetermined time period. For instance, the MX node 461 canremove messages (stored in the local buffer) with respective times ofpublication exceeding 3 minutes. In some implementations, thepredetermined time period for keeping messages in the local buffer on MXnode 461 can be the same as or similar to the TTL duration of astreamlet in the channel foo's channel stream, since at a given moment,messages retrieved from the channel's stream do not include those instreamlets having respective times-to-live that had already expired.

The messages retrieved from the channel stream 431 and sent to thesubscriber 480 (by the MX node 461) are arranged in the same order asthe messages were stored in the channel stream, although otherarrangements or ordering of the messages are possible. For instance,messages published to the channel foo are serialized and stored in thestreamlet 4102 in a particular order (e.g., M27, M31, M29, M30, and soon), then stored subsequently in the streamlet 4103 and the streamlet4104. The MX node retrieves messages from the channel stream 431 andprovides the retrieved messages to the subscriber 480 in the same orderas the messages are stored in the channel stream: M27, M31, M29, M30,and so on, followed by ordered messages in the streamlet 4103, andfollowed by ordered messages in the streamlet 4104.

Instead of retrieving all available messages in the channel stream 431,the MX node 461 can request a read grant for messages stored in thechannel stream 431 starting from a message at particular position, e.g.,position 47202. For instance, the position 47202 can correspond to anearlier time instance (e.g., 10 seconds before the current time) whenthe subscriber 480 was last subscribing to the channel foo (e.g., via aconnection to the MX node 461 or another MX node of the messaging system100). The MX node 461 can send to the channel manager 214 a request fora read grant for messages starting at the position 47202. Based on therequest, the channel manager 214 provides the MX node 461 a read grantto the streamlet 4104 (on the Q node 474) and a position on thestreamlet 4104 that corresponds to the channel stream position 47202.The MX node 461 can retrieve messages in the streamlet 4104 startingfrom the provided position, and send the retrieved messages to thesubscriber 480.

As described above in reference to FIGS. 4A and 4B, messages publishedto the channel foo are serialized and stored in the channel's streamletsin a particular order. The channel manager 214 maintains the orderedsequence of streamlets as they are created throughout their respectivetimes-to-live. Messages retrieved from the streamlets by an MX node(e.g., MX node 461, or MX node 468) and provided to a subscriber can be,in some implementations, in the same order as the messages are stored inthe ordered sequence of streamlets. In this way, messages sent todifferent subscribers (e.g., subscriber 480, subscriber 482, orsubscriber 485) can be in the same order (as the messages are stored inthe streamlets), regardless which MX nodes the subscribers are connectedto.

In various implementations, a streamlet stores messages in a set ofblocks of messages. Each block stores a number of messages. Forinstance, a block can store two hundred kilobytes of messages. Eachblock has its own TTL, which can be shorter than the TTL of thestreamlet holding the block. Once a block's TTL has expired, the blockcan be discarded from the streamlet holding the block, as described inmore detail below in reference to FIG. 4C.

FIG. 4C is an example data structure for storing messages of a channelof a messaging system. As described with the channel foo in reference toFIGS. 4A and 4B, assume that at the current moment the channel foo'schannel stream 432 includes active streamlets 4104 and 4105, as shown inFIG. 4C. Streamlet 4103 and streamlets before 4103 are invalid, as theirrespective TTLs have expired. The streamlet 4104 is already full for itscapacity (e.g., as determined by a corresponding write grant) and isclosed for additional message writes. The streamlet 4104 is stillavailable for message reads. The streamlet 4105 is open and is availablefor message writes and reads.

By way of illustration, the streamlet 4104 (e.g., a computing processrunning on the Q node 474 shown in FIG. 4B) currently holds two blocksof messages. Block 494 holds messages from channel positions 47301 to47850. Block 495 holds messages from channel positions 47851 to 48000.The streamlet 4105 (e.g., a computing process running on another Q nodein the messaging system 100) currently holds two blocks of messages.Block 496 holds messages from channel positions 48001 to 48200. Block497 holds messages starting from channel position 48201, and stillaccepts additional messages of the channel foo.

When the streamlet 4104 was created (e.g., by a write grant), a firstblock (sub-buffer) 492 was created to store messages, e.g., from channelpositions 47010 to 47100. Later on, after the block 492 had reached itscapacity, another block 493 was created to store messages, e.g., fromchannel positions 47111 to 47300. Blocks 494 and 495 were subsequentlycreated to store additional messages. Afterwards, the streamlet 4104 wasclosed for additional message writes, and the streamlet 4105 was createdwith additional blocks for storing additional messages of the channelfoo.

In this example, the respective TTL's of blocks 492 and 493 had expired.The messages stored in these two blocks (from channel positions 47010 to47300) are no longer available for reading by subscribers of the channelfoo. The streamlet 4104 can discard these two expired blocks, e.g., byde-allocating the memory space for the blocks 492 and 493. The blocks494 or 495 could become expired and be discarded by the streamlet 4104,before the streamlet 4104 itself becomes invalid. Alternatively,streamlet 4104 itself could become invalid before the blocks 494 or 495become expired. In this way, a streamlet can hold one or more blocks ofmessages, or contain no block of messages, depending on respective TTLsof the streamlet and blocks, for example.

A streamlet, or a computing process running on a Q node in the messagingsystem 100, can create a block for storing messages of a channel byallocating a certain size of memory space from the Q node. The streamletcan receive, from an MX node in the messaging system 100, one message ata time and store the received message in the block. Alternatively, theMX node can assemble (i.e., buffer) a group of messages and send thegroup of messages to the Q node. The streamlet can allocate a block ofmemory space (from the Q node) and store the group of messages in theblock. The MX node can also perform compression on the group ofmessages, e.g., by removing a common header from each message orperforming other suitable compression techniques.

As described earlier, an MX node can retrieve messages from Q nodes,store (cache) the retrieved messages in a local buffer, and provide theretrieved messages to multiple subscribers from the local buffer. Inthis way, the MX node can support a large number (e.g., thousands ormore) of subscribers (e.g., of a particular channel), without creating anetwork bottleneck at Q nodes where messages are stored (in streamlets).The messaging system 100 can further scale up the number of subscribersby adding additional MX nodes that each can cache messages and supportadditional subscribers.

When an MX node provides a locally cached message to multiplesubscribers, a sender process running on the MX node can send copies ofthe cached message to destination processes (running on the MX node)that each corresponds to a connection to one of the subscribers.However, with a large number (e.g., thousands) of subscribers, copies ofthe cached message (e.g., created by the sender process for differentdestination processes) can cause a high demand of memory usage on the MXnode. If the sender process sends the cached message sequentially todifferent destination processes, blocking (for synchronization) betweenthe destination processes can cause computing resource contention on theMX node.

Particular implementations described herein utilize a delivery buffer(i.e., a “fast buffer”) in an MX Node that can be used to cache messagesretrieved from a Q node. The fast buffer includes data blocks forstoring the retrieved messages. As described further below, each datablock has a respective TTL that is longer than a read operation timeassociated with reading data from the fast buffer. This may preventexpiration of the data block while data is being read from the bufferand/or sent to subscribers. In certain instances, the TTL of a datablock is longer than a corresponding streamlet's TTL. A process (runningon the MX node) for a subscriber can read messages stored in one or moreof the data blocks of the fast buffer, depending on the subscriber'sconnection status to the MX node. Processes for multiple subscribers canread messages from a single shared data structure (the fast buffer),without creating multiple copies for each message. In preferredimplementations, multiple MX nodes are able to read from the fast buffer(e.g., the same data) simultaneously, without blocking or interferingwith each other and without modifying the data in the fast buffer. Forexample, a first read process on the MX node can read messages from thefast buffer without blocking (e.g., causing suspension of) a second readprocess that is on the same MX node but may reside on a differentprocessor core of the MX node.

FIG. 5 is an example system 500 in which an MX node 502 retrievesmessages from a Q node 504 and provides the messages to a client device506 of a subscriber. The MX node 502 can include an MX subscribe process508 and a fast buffer 510. The MX subscribe process 508 can use aconnection 512 to read messages stored on the Q node 504 (e.g., in astreamlet) and can use a connection 514 to provide the messages to thefast buffer 510 for storage. The fast buffer 510 may store the messagesin one or more blocks, with each block having a TTL. In preferredimplementations, the fast buffer 510 can be a shared, lock-freestructure that holds the data blocks and expires old data periodically(e.g., when the old data is no longer being read by MX processes orrequested by subscribers or after a specified or predetermined timeperiod).

In certain examples, the MX node 502 can also include an MX connectprocess 516 and an MX send process 518 for establishing communicationswith one or more client devices, such as client device 506. In thedepicted example, the client device 506 connects to the MX connectprocess 516 using a connection 520 and requests messages from the MXnode 502 for one or more channels. The client device 506 can request,for example, messages of the channel foo starting at a particularposition, such as the position 47202. An example JSON version of thisspecific request is as follows:

{

-   -   “action”: “pubsub/subscribe”,    -   “body” }        -   “channel”: “foo”,        -   “position”: 47202    -   }

{

In response to the request, the MX connect process 516 sends aninstruction 524 to the MX send process 518 to retrieve message datastored in the fast buffer 510 (e.g., starting at the position 47202 ofthe channel foo). The MX send process 518 then retrieves the messagedata from the fast buffer 510 using a connection 526 and sends themessages to the client device 506 through a connection 522.

The MX subscribe process 508 and the fast buffer 510 are preferablyinstantiated on a per-channel basis and/or devoted to retrieving andstoring messages for a single channel. Additional MX subscribe processesand/or fast buffers may be included in the MX node 502 to retrieve andstore messages for additional channels. In alternative implementations,the MX subscribe process 508 and the fast buffer 510 can be configuredto retrieve and store messages for multiple channels. For example, theMX node 502 may include one MX subscribe process 508 and one fast buffer510 for retrieving and storing messages for the multiple channels.

Likewise, the MX connect process 516 and the MX send process 518 arepreferably instantiated on a per-client connection basis and/or devotedto establishing communications with a single client device (e.g., theclient device 506). Additional MX connect processes and MX sendprocesses may be included on the MX node 502 to establish communicationswith additional client devices and retrieve and send messages from oneor more fast buffers. In alternative implementations, the MX connectprocess 516 and MX send process 518 can be configured to connect withand serve multiple client devices. For example, the MX node 502 mayinclude one MX connect process 516 and one MX send process 518 forreceiving requests from client devices (including client device 506) andsending messages to the client devices (e.g., for one or more channels),respectively.

In general, the blocks of data delivered to the MX subscribe process 508from the Q node 504 can be stored in the fast buffer 510 in the sameorder as the blocks were received by the fast buffer 510, although otherarrangements or ordering of the data blocks are possible. The blocks arepreferably given an offset and a timestamp. This allows the blocks to belocated and retrieved from the fast buffer 510 and/or allows the MXsubscribe process 508 to identify any blocks that are older than theirTTL and/or otherwise unavailable for reading. Offsets are generallyassigned in ascending order, with blocks added one-by-one to a backportion of a single queue or linked list (e.g., a forward list) in thefast buffer 510.

In certain examples, when accessing or reviewing blocks in the fastbuffer 510, the MX subscribe process 508 may categorize each block asbeing, for example, active, inaccessible, or expired, although otherdesignations or categorizations are possible. In general, active blocksare “young” blocks whose TTLs have not expired. Active blocks reside ina visible or otherwise accessible area of the fast buffer 510 and may beaccessed with new read requests. Inaccessible blocks are “middle-aged”blocks whose TTLs are about to expire. Inaccessible blocks reside in aninvisible or otherwise restricted or no access area of the fast buffer510 and may be accessed only by read processes that have an establishedconnection (e.g., a previously granted read request). If the TTL of aninaccessible block expires during a read process, the block becomesexpired, but the read process may be given additional time to finishreading data from the block. Expired blocks reside in the invisible areaof the fast buffer 510 and are deleted periodically from the fast buffer510.

For example, when the MX subscribe process 508 determines that one ormore blocks are expired, the MX subscribe process 508 may shrink thequeue in the fast buffer 510. For example, the MX subscribe process 508may shrink a head, a tail, or other suitable portion of the fast buffer510, so that the expired blocks are removed from the queue and are nolonger accessible. In some implementations, however, expired blocks mayremain available for reading for additional time to accommodate certainprocesses that were unable to read messages from the blocks within theirTTLs. For example, client devices (and associated MX send processes)having a current or pre-existing connection to the MX node 502 (e.g., apre-existing read request) may be allowed to read data from inaccessibleand/or expired blocks. On the other hand, client devices (and associatedMX send processes) having a new connection to the MX node 502 (e.g.,with no pre-existing read request) may not be allowed to read data frominaccessible and/or expired blocks. Such client devices with newconnections may be limited to reading only active blocks that arepresently in a visible or accessible portion of the queue. This approachgives preference to pre-existing connections or pre-existing readrequests and allows the corresponding client devices to avoid any gapsin received message data. Such gaps may occur, for example, due to slowconnection speeds and/or temporary lapses in a connection. On the otherhand, new connections generally do not need to access the older blocksto fill in any gaps, because the new connections have not yet read anymessage data and can start by reading the unexpired blocks. In variousexamples, a “pre-existing connection” refers to a connection with whichan MX send process has requested and read messages from the fast buffer510. In various examples, a “new connection” refers to a connection withwhich an MX send process has not yet read any messages from the fastbuffer 510.

Advantageously, this approach of categorizing blocks and periodicallydeleting expired blocks provides improved control over memory usage. Theamount of memory used by channel data can be dynamically allocatedand/or can change over time according to demand. For example, as messageactivity for a channel decreases, the amount of memory used for thechannel can automatically decrease, as expired blocks are deleted andfewer new blocks are created. Also, expired blocks can be deleted afterexisting read processes have had a chance to read the message data andthe message data in the blocks is no longer needed. The approach alsoprovides flexibility to add one or more processing steps (e.g.,encryption, compression, etc.), and ensures that such steps are notprocessing or attempting to access memory that has been freed.

In preferred implementations, the MX subscribe process 508 can be theonly process having authority to modify the structure of the fast buffer510. For example, the MX subscribe process 508 may be configured andallowed to add blocks to the fast buffer 510, remove blocks from thefast buffer 510, and/or modify blocks on the fast buffer 510, as needed.The MX subscribe process 508 may also move pointers that identify a headportion and a tail portion of a queue or linked list in the fast buffer510. Other processes or MX node components are preferably not allowed toperform such modifications. By giving such authority only to the MXsubscribe process 508, the need for any locks in the modificationoperations is eliminated.

In certain examples, the MX send process 518 can check the front (i.e.,head) and back (i.e., tail) of the fast buffer 510 at the beginning ofevery read operation. When the MX send process 518 is requesting to reada target block, and the target block resides in an accessible or visibleregion of the fast buffer 510 (e.g., because the target block is anactive block), the MX send process 518 may read the block from the fastbuffer 510 and forward the message data in the block to the clientdevice 506. When the MX send process 518 is requesting to read data frommore than one block in the accessible region of the fast buffer 510, theMX send process 518 may read an amount of data (e.g., up to 64 Kb) fromthe fast buffer 510 (e.g., starting from a block having a requestedoffset or location in the fast buffer 510) and forward the message datato the client device 506. In certain instances, when the MX send process518 detects that a target data block is not accessible in the fastbuffer 510 (e.g., because the target block has expired), the MX sendprocess 518 may apply a separate logic that involves error reportingand/or waiting. The separate logic used by the MX send process 518 maydepend on where the target block resides in comparison to accessibleregions of the fast buffer 510.

For example, in some instances, when a client connection is too slow toremain in sync with fast moving channel data, the client may beunsubscribed from the channel and a message may be sent to inform thatclient that it is “out of sync” with the channel's data. Alternatively,rather than sending the “out of sync” message to the client, the clientmay be fast forwarded to the oldest data available (e.g., the oldestactive block) or to the newest data available (e.g., the newest activeblock). In certain instances, the systems and methods may identify oneor more key active blocks (e.g., as indicated by one or more flags),forward the data from the key active blocks to the client, and then fastforward the client to the newest active block for further reading. Theclient may have certain preferences that define how error reportingand/or waiting are to be performed. For example, the client may have apreference that causes its state to be reloaded completely (e.g., whenthe client loses a connection and is able to reconnect).

In various examples, the MX send process 518 can read the accessibleblocks in the fast buffer 510 and then can wait to be notified whenadditional blocks are added to the fast buffer 510 and available forreading. For example, when the MX send process 518 reaches a tail of thefast buffer 510, the MX send process 518 may turn on or activate anotifier 528 and/or yield to other processes. The notifier 528 can beconfigured to wake up the MX send process 518 upon the arrival of newdata into the fast buffer 510. To activate the notifier 528, the MX sendprocess 518 may send its process identifier (PID) or other suitableidentifier to a waiting list 530 along a connection 532. The MX sendprocess 518 may then perform a second check of the fast buffer 510 fornew data and, if no new data is present, the MX send process 518 may goto sleep and wait for a message from the notifier 528. Checking the fastbuffer 510 again after providing the PID to the waiting list 530 mayallow the MX send process 518 to identify the presence of any new datathat arrived just before or at around the same time as the PID was addedto the waiting list 530. In general, the waiting list 530 includes alist of PIDs for one or more MX send processes that are waiting to benotified when new data arrives in the fast buffer 510. The waiting list530 may provide PIDs to the notifier 528 along a connection 534, and thenotifier 528 may wake up or notify the MX send processes in the waitinglist 530 when new data arrives in the fast buffer 510 and is availablefor reading. For example, the notifier 528 may wake up the MX sendprocess 518 by sending a notification along a connection 536. Like theMX subscribe process 508 and the fast buffer 510, the waiting list 530and the notifier 528 are preferably configured to perform operations fora single channel. The MX node 502 may include additional waiting listsand notifiers to perform operations for additional channels. Inalternative implementations, the waiting list 530 and the notifier 528can be configured to perform operations for multiple channels. Forexample, the MX node 502 may include one waiting list 530 and onenotifier 528 for receiving PIDs of MX send processes and waking up thecorresponding MX send processes, respectively, when new data arrives inthe fast buffer 510 for the multiple channels.

In preferred examples, the notifier 528 can work together and/or can besynchronized with the MX subscribe process 508. When a new block of datais added to the fast buffer 510, the notifier 528 may receive a list ofPIDs from the waiting list 530 for the one or more MX send processeswaiting to be notified. The notifier 528 then delivers a notification tothe one or more MX send processes. The notification preferably includesthe offset or location of the new block in the fast buffer 510. Aftersending the notifications, the PIDs for the one or more MX sendprocesses may be removed from the waiting list 530.

In certain implementations, to keep the latency low, the notifier 528can use a two-level model of synchronization with the MX subscribeprocess 508. In an inner loop 538, the notifier 528 may contact the MXsubscribe process 508 at short time intervals (e.g., every 10 ms) todetermine if any new blocks have been added to the fast buffer 510. Thenotifier 528 may, for example, read from a dictionary or log of the MXsubscribe process 508 to determine the offset of the block most recentlyadded to the fast buffer 510. If the most recent block has not changedfor more than a threshold amount of time (e.g., more than 200 ms), thenotifier 528 may switch to an outer loop 540 where the notifier 528 goesto sleep and/or waits for a notification from the MX subscribe process508. In the outer loop 540, the MX subscribe process 508 preferablychecks the state of the notifier 528 and wakes up the notifier 528 bysending a notification when the notifier 528 is sleeping and new datahas been sent to the fast buffer 510. In general, since checking thestate of the notifier 528 is a significantly faster operation thandelivering the notification, this approach allows the MX subscribeprocess 508 to look for new data on the Q node more frequently and toadd any such new data to the fast buffer 510. When the MX subscribeprocess 508 informs the notifier 528 that a new block has been added tothe fast buffer 510, the notifier 528 may switch back to the inner loop538. The two-loop approach allows the MX node 502 to conserve resourcesand operate more efficiently. The notifier 528 actively looks for newmessage data only when message data is being added to the fast bufferfrequently. Otherwise, the notifier 528 is able to sleep and is woken upby the MX subscribe process 508 when new data arrives. A primary benefitof the two-loop approach is that resources are used only when there iswork to do or when work is expected in the near future. If new channeldata is not expected soon, the system switches from the inner loop 538to the use of push notifications in the outer loop 540. The two-loopapproach achieves a good balance between latency and central processingunit (CPU) overhead. The outer loop 540 allows the system to maintainmillions of channels that are rarely updated and not waste a single CPUcycle on checking the status of such channels. At the same time, theinner loop 538 allows the system to maintain with minimal latency otherchannels that are updated more frequently.

In certain implementations, when the notifier 528 becomes aware of newdata added to the fast buffer 510, the notifier 528 sends a notificationto any MX send processes waiting for the new data. For example, thenotifier 528 may obtain from the waiting list 530 the PIDs of MX sendprocesses that are sleeping and waiting for new data and may sendnotifications to those MX send processes. The notifications preferablyinclude the offset or other location information for any new blocks ofdata in the fast buffer 510.

In various examples, the systems and methods allow publishers to beprioritized (or deprioritized) with respect to subscribers. For example,the fast buffer 510 can be considered to (i) receive data frompublishers in a publishing loop and (ii) provide data to subscribers ina subscribing loop. The publishing loop can include, for example, a stepof obtaining new message data from one or more publishers and a step ofwriting the new message data to the fast buffer 510. The subscribingloop can include, for example, a step of checking the fast buffer 510for new data and a step of providing the new data to one or moresubscribers (e.g., using the MX send process 518). In preferredexamples, the publishing loop and the subscribing loop are looselycoupled or not coupled, such that publishing and subscribing speeds canbe independently controlled and/or prioritized. This allows a publishingspeed to be different from a subscribing speed, if desired, and/or foreach speed to be chosen or prioritized, for example, according to systemload. To promote publishing activity, for example, the steps of thepublishing loop can be performed faster, so that message data can bewritten more frequently to the fast buffer 510. Alternatively oradditionally, to promote subscribing activity, the steps of thesubscribing loop can be performed faster, so that message data can beread more frequently from the fast buffer 510. In general, when thesteps of one loop are performed faster, the steps of the other loop canbe performed slower, for example, to maintain overall system load at ornear a constant value and/or to avoid excessive system load. Suchprioritization can be achieved, for example, by creating two workerpools (e.g., one pool for publishers and one pool for subscribers) andusing an operating system kernel scheduler prioritization mechanism toset different priorities to threads in the two pools. Other approachesfor prioritizing or deprioritzing publishers and subscribers arecontemplated.

FIG. 6 shows example data blocks of the fast buffer 510 at differentinstances in time. At a first time 650, the fast buffer 510 includes asequence of data blocks 601, 602, . . . , 608, that were retrieved fromone or more streamlets in the Q node 504. The sequence of message datain the data blocks is preferably consistent with or the same as thesequence of message data from the one or more streamlets in the Q node504.

Each data block 601, 602, . . . , 608 in the fast buffer 510 is given arespective TTL. In preferred implementations, the TTLs for the blocksare sufficient in duration to give read processes enough time to readdata from the blocks. In some instances, the TTLs for one or more blocksare longer than the TTLs for one or more streamlets in the Q node 504.In general, the TTLs for the blocks are chosen to give the MX sendprocesses adequate time to read from the fast buffer 510. In oneexample, the TTL for the blocks in the fast buffer 510 is about 30seconds or about 60 seconds, while the TTL for the streamlets in the Qnode 504 is about 10 seconds, although other TTLs for the blocks and thestreamlets are possible. This way, the fast buffer 510 (on the MX node502) can hold more messages (e.g., messages for the past 30 seconds)than the streamlets can hold (e.g., messages for the past 10 seconds)for the particular channel. The MX node 502 can thus provide a longerhistory of messages to client devices of subscribers (e.g., clientdevice 506). This is beneficial, for example, when a client device has aslower connection and/or otherwise takes longer (e.g., exceeding 10seconds) to read messages that may no longer be accessible or stored instreamlets of the Q node 504.

In various examples, there can be three global always-accessiblepointers inside the fast buffer 510: a tail pointer 642 identifying arightmost block of a visible area 662 (i.e., block 608 at time 650), ahead pointer 640 identifying a leftmost block of the visible area 662(i.e., block 603 at time 650), and a previous head pointer 644identifying a leftmost block of an invisible area 660 (i.e., block 601at time 650). All blocks referenced by pointers represent a singlelinked list (e.g., a forward list) so all such pointers can be reachedby iterating from a first block in the list (e.g., block 601 at time650) using the block's next pointer. In certain examples, the visiblearea 662 includes blocks that are active and the invisible area 660includes blocks that are inaccessible and/or expired.

In the sequence of data blocks of the fast buffer 510, data blockscloser to the head pointer 640 of the fast buffer 510 have been in thefast buffer 510 longer than blocks closer to the tail pointer 642 of thefast buffer 510. Accordingly, blocks near the head pointer 640 willgenerally reach their respective TTLs and expire before blocks near thetail pointer 642 reach their TTLs and expire. For instance, at the firsttime 650, block 603 will expire before block 604, which will expirebefore block 605, and so on. In general, messages in the fast buffer 510are arranged in the same order as the messages were arranged in the Qnode 504, although other arrangements or ordering of the messages arepossible. Accordingly, the messages may expire in the fast buffer 510 inthe same order that the messages expire in the Q node 504.

In preferred implementations, the sequence of data blocks of the fastbuffer 510 can be arranged as a linked list 620. In the linked list 620,each data block has a pointer pointing to the next data block in thesequence of the list. For instance, data block 604 has a pointerpointing to data block 605, which has a pointer pointing to data block606. Data block 608, located at a tail end of the linked list 620, mayhave a pointer (e.g., NUL) indicating that it is at the tail end of thelinked list 620. In one implementation, the linked list 620 includes thehead pointer 640 identifying the block at the head of the linked list620. At time 650, for example, the linked list 620 may have a headpointer 640 identifying data block 603, which has not reached its TTLbut will be the next block in the linked list 620 to expire.

In certain instances, when the MX subscribe process 508 adds data to thefast buffer 510, the MX subscribe process 508 can do two things. First,the MX subscribe process 508 can determine the age of the oldestblock(s) in the visible area 662 (i.e., block 603 at time 650), todetermine whether the oldest block(s) should be moved to the invisiblearea 660. If one or more blocks in the visible area 662 are inaccessible(i.e., because their TTLs will expire soon) or have expired, the MXsubscribe process 508 may move the one or more blocks to the invisiblearea 660 or delete the one or more blocks from the fast buffer 510. Inone example, blocks that are inaccessible are moved to the invisiblearea 660 and blocks that have expired are deleted. The process ofdeleting or removing one or more blocks from the fast buffer 510 may bereferred to herein as “shrinking”. Next, the MX subscribe process 508can add one or more blocks of the data to a tail of the fast buffer 510.

In preferred examples, the shrinking and adding processes are donewithout the use of locks or atomic operations, and resulting changes arepreferably made in a conflict free order. In general, locks or atomicoperations are a significant source of poor performance on symmetricmultiprocessing (i.e., SMP or multi core) systems. Every such operationmust ensure that core or non-uniform memory access (NUMA) node caches donot have a cached value that can be read right after a change was made.Locks and/or atomic operations are expensive on modern CPUs and can costhundreds of CPU cycles. By relying on time, however, the fast buffer 510performs truly in parallel, such that multiple read processes can readfrom the same memory simultaneously. With the fast buffer approachdescribed herein, preferably nothing other than boundary pointersrequires a synchronization during the shrinking and adding processes.

Referring to times 650 and 652 in FIG. 6, shrinking is preferably donewith the following technique. First, expired blocks in the invisiblearea 660 are deleted. In some examples, expired or inaccessible blocksin the invisible area 660 that are younger than some threshold time(e.g., TTL*1.5) are retained in the invisible area 660. The previoushead pointer 644 is then moved to the current location of the headpointer 640, and the head pointer 640 is moved toward the tail pointer642 until a block is found that is active (e.g., block 605 at time 652).The head pointer 640 is placed at the front edge of that first activeblock. If no active blocks are found, the head pointer 640 and the tailpointer 642 may mark the same location, indicating that the fast buffer510 includes no active blocks.

The shrinking process is further illustrated at times 652, 654, and 658for the fast buffer 510 in FIG. 6. At time 652, the head pointer 640 andprevious head pointer 644 have been moved, such that expired blocks 601and 602 have been removed and no longer reside in the invisible area660, and the invisible area 660 now includes blocks 603 and 604. Thetail pointer 642 has also been moved to define a new tail at block 611.Likewise, at time 654, the head pointer 640 and the previous headpointer 644 have been moved, such that expired blocks 603 and 604 havebeen removed and no longer reside in the invisible area 660. At thistime, the invisible area 660 includes no blocks and the head pointer 640and the previous head pointer 644 mark the same location (i.e., block605 at time 654). Each block in the fast buffer 510 at time 654 isactive and resides in the visible area 662. Further, at time 658, thehead pointer 640 and the previous head pointer 644 have been moved, suchthat expired blocks 605 and 606 have been removed and no longer residein the invisible area 660. The invisible area 660 at that time includesblocks 607 and 608, and the previous head pointer 644 has been moved toidentify the leftmost block of the invisible area 660 (i.e., block 607at time 658). The tail pointer 642 at time 658 has been moved to definea new tail at block 615, while the head pointer 640 at time 658 has beenmoved to define a new head at block 609.

In general, because there are typically many MX send processes readingfrom the fast buffer 510 in parallel, shrinking the fast buffer 510 andrepositioning the pointers preferably occurs while certain MX sendprocesses continue to have access to blocks in the new invisible area660. The invisible area 660 (e.g., including blocks 603 and 604 at time652) may therefore be left accessible to existing MX send processes andnot freed instantly. This allows existing read requests for MX sendprocesses to continue accessing inaccessible and/or expired blocks afterthe blocks have been moved from the visible area 662 to the invisiblearea 660.

On the other hand, MX send processes that are new and/or have new readrequests may be given access only to the active blocks in the visiblearea 662 of the fast buffer 510. In preferred examples, each MX sendprocess (e.g., MX send process 518) having a new read request checks theboundaries of the visible area 662 and if the process requests accessoutside of the visible area 662 (e.g., to any blocks between theprevious head and the head), the request fails as if there were no dataavailable for the request. In general, MX send processes having newrequests are not allowed to access any inaccessible or expired blocks inthe invisible area 660. In preferred examples, the invisible area 660can be accessed only by MX send processes having old requests, and theMX send processes preferably finish the read operation from theinvisible area 660 as soon as possible. Typical reading times take a fewmicroseconds or milliseconds, because there are preferably no locks inthe reading code.

In general, blocks reside in the visible area 662 for approximately oneTTL and are then moved to the invisible area 660 where the blocks residefor some fraction (e.g., 0.25, 0.5, or 0.75) of the TTL. For example,after spending approximately one TTL in the visible area 662, a blockmay reside in the invisible area 660 for an additional TTL*0.5. Thistime in the invisible area 660 is generally many orders of magnitudelonger than a typical access time and provides pre-existing MX sendprocesses with additional time to obtain the requested message data. Asdiscussed previously, a block resides in the visible area 662 when theblock is active and is moved to the invisible area 660 when the block isinaccessible or expired.

In one example, to add blocks to the fast buffer 510, new blocks arecombined into a separate single linked list 620 that is linked to theblock identified by the current tail pointer 642. The tail pointer 642is then moved to the last added block. This block addition process isillustrated in FIG. 6 at times 652, 656, and 658. At each of thesetimes, new blocks have been added to the fast buffer 510, compared tothe previous time, and the tail pointer 642 has been moved to identifythe last added block. For example, at time 652, new blocks 609, 610, and611 have been added and the tail pointer 642 points to the right-handedge of block 611, indicating that block 611 is the last added block.Likewise, at time 656, new blocks 612 and 613 have been added, and thetail pointer 642 indicates block 613 is the last added block. Further,at time 658, blocks 614 and 615 have been added, and the tail pointer642 indicates block 615 is the last added block.

In certain instances, a data block contains zero messages and may serveas a gap block or a left boundary marker. Gap blocks may be used whenthere is a gap in block positions in the fast buffer 510 (e.g., when aprevious block position plus a previous block length does not equal anext block position). Such gaps can be due to, for example, switchingfrom one streamlet to another streamlet (e.g., streamlets that are 16 min size can be aligned by a 16 m boundary) or missing data, in whichcase clients reaching the gap in the buffer may need to be informedabout and/or provided with the missing data. A left boundary marker maybe a zero message block or marker that indicates the leftmost availablelocation in the fast buffer 510 where data was first written or intendedto be written. The zero message block may contain the leftmost offseteven when no data is available yet. In such instances, the left boundarymarker can help the MX node 502 make decisions about certain readrequests and whether it will be possible to provide a client device withthe requested data. Having the left boundary defined for every readrequest may make it possible to determine whether the read request canbe satisfied in the future (e.g., when data is received) or not.

In general, the fast buffers described herein are internal componentsinside a distributed PubSub system. While fast buffers can be includedin or used by MX nodes, as shown in FIG. 5, fast buffers can also beincluded in or used by other system components, including Q nodes. Afast buffer publisher is, in general, a component that writes data to afast buffer, and a fast buffer subscriber is a component that reads datafrom a fast buffer. As shown in FIG. 5, for example, the MX subscribeprocess 508 is a fast buffer publisher and the MX send process 518 is afast buffer subscriber, for the fast buffer 510 in MX node 502. Similarfast buffer publishers and fast buffer subscribers can be used for Qnodes. In one example, a Q node fast buffer publisher is referred to asa Q streamlet process and a Q node fast buffer subscriber is referred toas a Q sender process. Fast buffers incorporated into or used by Q nodescan use the notifier and/or waiting list approach described herein withrespect to MX node 502. For example, a Q sender process waiting toretrieve new message data from a Q node fast buffer can be put to sleepwhen no data is available and/or woken up when new message data arrives.

FIG. 7 is a flowchart of example method 700 for providing messages to aplurality of subscribers. The method includes receiving (step 702) froma plurality of publishers a plurality of messages. Each of the messagesis assigned (step 704) to one of a plurality of distinct channelswherein each channel includes an ordered plurality of messages. Themessages of each of the channels are stored (step 706) in one or morerespective storage buffers according to the order. Each storage bufferhas a respective time-to-live of a first time duration. For a particularchannel, messages of the particular channel are retrieved (step 708)from respective storage buffers (e.g., those having times-to-live thathave not expired and according to the order). The retrieved messages ofthe particular channel are stored (step 710) in a delivery bufferaccording to the order. The delivery buffer includes one or more datablocks, and each data block has a respective time-to-live of a secondtime duration (e.g., that is longer than the first time duration). Themessages stored in the delivery buffer are provided (step 712) to aplurality of subscribers of the particular channel.

Examples of the systems and methods described are able to send a streamof data from one source (e.g., an ERLANG process) to multipledestinations (e.g., ERLANG processes). The stream of data is deliveredat a high rate (e.g., in messages per second) and with low latency(e.g., 99% of messages are delivered with a latency less than 50 ms).

A first alternative approach involves sending messages sequentially froma sender process to all the destination processes, which may berepresented as a list or other data structure. This process is generallyslow and measured to be a bottleneck, for example, because locking onmulticore processing can create a contention point around sending amessage to processes running on other cores. The process also requires alot of memory because every sending operation creates a copy of data tobe sent (or a copy of reference to the data). The copy typically residesin the destination process message queue until the destination processhandles the data. Using multiple senders does not solve the problem.

A second alternative approach is to use a table storage (e.g., an ERLANGETS) as an intermediary single-copy storage of the stream data and letevery destination process read the data from various places at the sametime. This approach is also slow, however, because access to the tablestorage presents a bottleneck. For example, ERLANG ETS tables utilize aset of locks to protect ranges of keys from multiple accesses and orderthese accesses. There is also a step of determining a location for datain the ETS table, given that every call to the ETS table is done with anETS table identifier. Both of these locks are expensive and make itdifficult to exceed 10 million updates per second to a table, no matterhow many keys and cores (on modern hardware) are used. If locks areeliminated, the number of accesses or processing tasks can be reduced byseveral orders of magnitude.

A series of tests were performed to compare these first and secondalternative approaches with the fast buffer approach described herein.The tests involved using all three approaches to send 100 byte messagesfrom one publisher to multiple receivers on a 32-core server. The numberof receivers was selected from 100, 1,000, or 10,000. The results of thetests are presented in Table 1, below, which includes the resultingnumber of messages per second each approach was able to send.

TABLE 1 Comparison of Fast Buffer approach with two alternativeapproaches. 1 Publisher to 100 1 Publisher to 1,000 1 Publisher to10,000 Subscribers Subscribers Subscribers Published Received PublishedReceived Published Received Rate Rate Rate Rate Rate Rate Approach(msgs/sec) (msgs/sec) (msgs/sec) (msgs/sec) (msgs/sec) (msgs/sec) FirstAlternative 400k 400k 380k 380k 350k 350k Approach - Publisher sendsmessages to subscribers Second Alternative 5000 0.5m 2200  2.2m 1280  5mApproach - Publisher writes messages to ETS, subscribers read messagesfrom ETS Fast Buffer (FB) 160k  16m 160k  160m  83k 830m Approach -Publisher writes messages to FB, subscribers read messages from FB

In various implementations, rather than sending message data to multipleprocesses from a single process, the fast buffer approach describedherein tasks the receivers or subscribers themselves to grab data from asingle shared structure (i.e., a fast buffer). To avoid having lockingissues around the shared structure, the process utilizes a “lock-free”or non-blocking approach. Receivers are able to grab many pieces of datawithout blocking or figuring out where to read from and up to whichpoint. As the results in Table 1 indicate, the rates of message transferare improved considerably when compared to the alternative approaches.

Embodiments of the subject matter and the operations described in thisspecification can be implemented in digital electronic circuitry, or incomputer software, firmware, or hardware, including the structuresdisclosed in this specification and their structural equivalents, or incombinations of one or more of them. Embodiments of the subject matterdescribed in this specification can be implemented as one or morecomputer programs, i.e., one or more modules of computer programinstructions, encoded on computer storage medium for execution by, or tocontrol the operation of, data processing apparatus. Alternatively or inaddition, the program instructions can be encoded on anartificially-generated propagated signal, e.g., a machine-generatedelectrical, optical, or electromagnetic signal, that is generated toencode information for transmission to suitable receiver apparatus forexecution by a data processing apparatus. A computer storage medium canbe, or be included in, a computer-readable storage device, acomputer-readable storage substrate, a random or serial access memoryarray or device, or a combination of one or more of them. Moreover,while a computer storage medium is not a propagated signal, a computerstorage medium can be a source or destination of computer programinstructions encoded in an artificially-generated propagated signal. Thecomputer storage medium can also be, or be included in, one or moreseparate physical components or media (e.g., multiple CDs, disks, orother storage devices).

The operations described in this specification can be implemented asoperations performed by a data processing apparatus on data stored onone or more computer-readable storage devices or received from othersources.

The term “data processing apparatus” encompasses all kinds of apparatus,devices, and machines for processing data, including by way of example aprogrammable processor, a computer, a system on a chip, or multipleones, or combinations, of the foregoing. The apparatus can includespecial purpose logic circuitry, e.g., an FPGA (field programmable gatearray) or an ASIC (application-specific integrated circuit). Theapparatus can also include, in addition to hardware, code that createsan execution environment for the computer program in question, e.g.,code that constitutes processor firmware, a protocol stack, a databasemanagement system, an operating system, a cross-platform runtimeenvironment, a virtual machine, or a combination of one or more of them.The apparatus and execution environment can realize various differentcomputing model infrastructures, such as web services, distributedcomputing and grid computing infrastructures.

A computer program (also known as a program, software, softwareapplication, script, or code) can be written in any form of programminglanguage, including compiled or interpreted languages, declarative,procedural, or functional languages, and it can be deployed in any form,including as a stand-alone program or as a module, component,subroutine, object, or other unit suitable for use in a computingenvironment. A computer program may, but need not, correspond to a filein a file system. A program can be stored in a portion of a file thatholds other programs or data (e.g., one or more scripts stored in amarkup language resource), in a single file dedicated to the program inquestion, or in multiple coordinated files (e.g., files that store oneor more modules, sub-programs, or portions of code). A computer programcan be deployed to be executed on one computer or on multiple computersthat are located at one site or distributed across multiple sites andinterconnected by a communication network.

The processes and logic flows described in this specification can beperformed by one or more programmable processors executing one or morecomputer programs to perform actions by operating on input data andgenerating output. The processes and logic flows can also be performedby, and apparatus can also be implemented as, special purpose logiccircuitry, e.g., an FPGA (field programmable gate array) or an ASIC(application-specific integrated circuit).

Processors suitable for the execution of a computer program include, byway of example, both general and special purpose microprocessors, andany one or more processors of any kind of digital computer. Generally, aprocessor will receive instructions and data from a read-only memory ora random access memory or both. The essential elements of a computer area processor for performing actions in accordance with instructions andone or more memory devices for storing instructions and data. Generally,a computer will also include, or be operatively coupled to receive datafrom or transfer data to, or both, one or more mass storage devices forstoring data, e.g., magnetic disks, magneto-optical disks, opticaldisks, or solid state drives. However, a computer need not have suchdevices. Moreover, a computer can be embedded in another device, e.g., asmart phone, a mobile audio or video player, a game console, a GlobalPositioning System (GPS) receiver, or a portable storage device (e.g., auniversal serial bus (USB) flash drive), to name just a few. Devicessuitable for storing computer program instructions and data include allforms of non-volatile memory, media and memory devices, including, byway of example, semiconductor memory devices, e.g., EPROM, EEPROM, andflash memory devices; magnetic disks, e.g., internal hard disks orremovable disks; magneto-optical disks; and CD-ROM and DVD-ROM disks.The processor and the memory can be supplemented by, or incorporated in,special purpose logic circuitry.

To provide for interaction with a user, embodiments of the subjectmatter described in this specification can be implemented on a computerhaving a display device, e.g., a CRT (cathode ray tube) or LCD (liquidcrystal display) monitor, for displaying information to the user and akeyboard and a pointing device, e.g., a mouse, a trackball, a touchpad,or a stylus, by which the user can provide input to the computer. Otherkinds of devices can be used to provide for interaction with a user aswell; for example, feedback provided to the user can be any form ofsensory feedback, e.g., visual feedback, auditory feedback, or tactilefeedback; and input from the user can be received in any form, includingacoustic, speech, or tactile input. In addition, a computer can interactwith a user by sending resources to and receiving resources from adevice that is used by the user; for example, by sending web pages to aweb browser on a user's client device in response to requests receivedfrom the web browser.

Embodiments of the subject matter described in this specification can beimplemented in a computing system that includes a back-end component,e.g., as a data server, or that includes a middleware component, e.g.,an application server, or that includes a front-end component, e.g., aclient computer having a graphical user interface or a Web browserthrough which a user can interact with an implementation of the subjectmatter described in this specification, or any combination of one ormore such back-end, middleware, or front-end components. The componentsof the system can be interconnected by any form or medium of digitaldata communication, e.g., a communication network. Examples ofcommunication networks include a local area network (“LAN”) and a widearea network (“WAN”), an inter-network (e.g., the Internet), andpeer-to-peer networks (e.g., ad hoc peer-to-peer networks).

The computing system can include clients and servers. A client andserver are generally remote from each other and typically interactthrough a communication network. The relationship of client and serverarises by virtue of computer programs running on the respectivecomputers and having a client-server relationship to each other. In someembodiments, a server transmits data (e.g., an HTML page) to a clientdevice (e.g., for purposes of displaying data to and receiving userinput from a user interacting with the client device). Data generated atthe client device (e.g., a result of the user interaction) can bereceived from the client device at the server.

A system of one or more computers can be configured to performparticular operations or actions by virtue of having software, firmware,hardware, or a combination of them installed on the system that inoperation causes or cause the system to perform the actions. One or morecomputer programs can be configured to perform particular operations oractions by virtue of including instructions that, when executed by dataprocessing apparatus, cause the apparatus to perform the actions.

While this specification contains many specific implementation details,these should not be construed as limitations on the scope of anyinventions or of what may be claimed, but rather as descriptions offeatures specific to particular embodiments of particular inventions.Certain features that are described in this specification in the contextof separate embodiments can also be implemented in combination in asingle embodiment. Conversely, various features that are described inthe context of a single embodiment can also be implemented in multipleembodiments separately or in any suitable subcombination. Moreover,although features may be described above as acting in certaincombinations and even initially claimed as such, one or more featuresfrom a claimed combination can in some cases be excised from thecombination, and the claimed combination may be directed to asubcombination or variation of a subcombination.

Similarly, while operations are depicted in the drawings in a particularorder, this should not be understood as requiring that such operationsbe performed in the particular order shown or in sequential order, orthat all illustrated operations be performed, to achieve desirableresults. In certain circumstances, multitasking and parallel processingmay be advantageous. Moreover, the separation of various systemcomponents in the embodiments described above should not be understoodas requiring such separation in all embodiments, and it should beunderstood that the described program components and systems cangenerally be integrated together in a single software product orpackaged into multiple software products.

Thus, particular embodiments of the subject matter have been described.Other embodiments are within the scope of the following claims. In somecases, the actions recited in the claims can be performed in a differentorder and still achieve desirable results. In addition, the processesdepicted in the accompanying figures do not necessarily require theparticular order shown, or sequential order, to achieve desirableresults. In certain implementations, multitasking and parallelprocessing may be advantageous.

What is claimed is:
 1. A computer-implemented method, comprising:assigning each of a plurality of messages to one of a plurality ofchannels; storing messages of each of the channels in one or morerespective storage buffers according to an order, wherein each storagebuffer comprises a respective time-to-live of a first time duration;retrieving messages of a particular channel from respective storagebuffers; storing the retrieved messages of the particular channel in adelivery buffer according to the order, wherein the delivery buffercomprises one or more data blocks, and wherein each data block comprisesa respective time-to-live of a second time duration; and providing themessages stored in the delivery buffer to a plurality of subscribers ofthe particular channel.
 2. The method of claim 1, wherein storing theretrieved messages of the particular channel in the delivery bufferaccording to the order comprises: storing retrieved messages of theparticular channel earlier in the order in data blocks havingtimes-to-live that will expire sooner than data blocks used to storeretrieved messages of the particular channel later in the order.
 3. Themethod of claim 1, wherein the delivery buffer comprises a linked listof the data blocks, and wherein retrieved messages last in the order ofthe particular channel are stored in a tail data block of the linkedlist.
 4. The method of claim 1, wherein providing the messages stored inthe delivery buffer to the plurality of subscribers of the particularchannel comprises: determining a connection status of a particularsubscriber; and based thereon, providing one or more of the messagesstored in the delivery buffer to the particular subscriber.
 5. Themethod of claim 1, wherein the delivery buffer resides on a firstcomputing node, and wherein the storage buffers reside on respectivesecond computing nodes that are different from the first computing node.6. The method of claim 1, wherein the delivery buffer comprises avisible area and an invisible area.
 7. The method of claim 1, furthercomprising: receiving the plurality of messages from a plurality ofpublishers.
 8. The method of claim 3, wherein storing the retrievedmessages of the particular channel in the delivery buffer according tothe order comprises: removing from the linked list one or more datablocks at a head of the linked list, wherein the removed data blockscomprise respective times-to-live that have expired.
 9. The method ofclaim 6, wherein a subscriber with a pre-existing connection ispermitted to access data from both the visible area and the invisiblearea.
 10. The method of claim 6, wherein a subscriber with a newconnection is permitted to access data from the visible area and notpermitted to access data from the invisible area.
 11. A system,comprising: one or more computer processors programmed to performoperations to: assign each of a plurality of messages to one of aplurality of channels; store messages of each of the channels in one ormore respective storage buffers according to an order, wherein eachstorage buffer comprises a respective time-to-live of a first timeduration; retrieve messages of a particular channel from respectivestorage buffers; store the retrieved messages of the particular channelin a delivery buffer according to the order, wherein the delivery buffercomprises one or more data blocks, and wherein each data block comprisesa respective time-to-live of a second time duration; and provide themessages stored in the delivery buffer to a plurality of subscribers ofthe particular channel.
 12. The system of claim 11, wherein to store theretrieved messages of the particular channel in the delivery bufferaccording to the order, the one or more computer processors to: storeretrieved messages of the particular channel earlier in the order indata blocks having times-to-live that will expire sooner than datablocks used to store retrieved messages of the particular channel laterin the order.
 13. The system of claim 11, wherein the delivery buffercomprises a linked list of the data blocks, and wherein retrievedmessages last in the order of the particular channel are stored in atail data block of the linked list.
 14. The system of claim 11, whereinto provide the messages stored in the delivery buffer to the pluralityof subscribers of the particular channel, the one or more computerprocessors to: determine a connection status of a particular subscriber;and based thereon, provide one or more of the messages stored in thedelivery buffer to the particular subscriber.
 15. The system of claim11, wherein the delivery buffer resides on a first computing node, andwherein the storage buffers reside on respective second computing nodesthat are different from the first computing node.
 16. The system ofclaim 11, wherein the delivery buffer comprises a visible area and aninvisible area.
 17. The system of claim 13, wherein to store theretrieved messages of the particular channel in the delivery bufferaccording to the order, the one or more computer processors to: removefrom the linked list one or more data blocks at a head of the linkedlist, wherein the removed data blocks comprise respective times-to-livethat have expired.
 18. The system of claim 16, wherein a subscriberdevice with a pre-existing connection is permitted to access data fromboth the visible area and the invisible area.
 19. The system of claim16, wherein a subscriber device with a new connection is permitted toaccess data from the visible area and not permitted to access data fromthe invisible area.
 20. A non-transitory computer-readable medium havinginstructions stored thereon that when executed by one or more computerprocessors, cause the one or more computer processors to: assign each ofa plurality of messages to one of a plurality of channels; store, by theone or more computer processors, messages of each of the channels in oneor more respective storage buffers according to an order, wherein eachstorage buffer comprises a respective time-to-live of a first timeduration; retrieve messages of a particular channel from respectivestorage buffers; store the retrieved messages of the particular channelin a delivery buffer according to the order, wherein the delivery buffercomprises one or more data blocks, and wherein each data block comprisesa respective time-to-live of a second time duration; and provide, by theone or more computer processors, the messages stored in the deliverybuffer to a plurality of subscribers of the particular channel.